﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

/// <summary>
/// This page hosts the Silverlight Photo Browser
/// See aspx file also!!!!
/// </summary>
public partial class PhotoBrowserPage : System.Web.UI.Page 
{
    /// <summary>
    /// Handles the Load event of the Page control.
    /// </summary>
    /// <param name="sender">The source of the event.</param>
    /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
    protected void Page_Load(object sender, EventArgs e)
    {
        //retrieves the album identifier from query string or
        //session variable
        if (!this.IsPostBack)
        {
            if (!string.IsNullOrEmpty(this.Request["ID"]))
                this.AlbumID = this.Request["ID"];
            else if (!string.IsNullOrEmpty(this.Session["AlbumID"] as string))
                this.AlbumID = this.Session["AlbumID"] as string;
        }
    }

    /// <summary>
    /// Gets or sets the album identifier that will be displayed by photo browser.
    /// </summary>
    /// <value>The album ID.</value>
    public string AlbumID
    {
        get { return this.ViewState["AlbumID"] as string; }
        set { this.ViewState["AlbumID"] = value; }
    }

    /// <summary>
    /// Creates and gets the absolute URL of web service.
    /// </summary>
    /// <returns></returns>
    protected string GetServiceUrl()
    {
        Uri currentUri = HttpContext.Current.Request.Url;
        UriBuilder uriBuilder = new UriBuilder(currentUri.Scheme, currentUri.Host, currentUri.Port);
        uriBuilder.Path = this.Page.ResolveUrl("PhotoBrowserService.asmx");
        string serviceUrl = uriBuilder.ToString();

        return serviceUrl;
    }
}
